/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package is202.hrms.web;

import is202.hrms.ejb.UserEJB;
import is202.hrms.entity.Usere;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;

/**
 *
 * @author group tre musketter
 */
@Named("userlistbean")
@RequestScoped
public class UserListBean implements Serializable {
    private static final long serialVersionUID = 1L;

    @EJB UserEJB userEjb;
    private String search;
    private List<Usere> users;

    public UserListBean() {
    }

    public List<Usere> getUsers() {
        if(users == null){
        getFindUsers();
        }
        return users;
    }

    public void setUsers(ArrayList<Usere> users) {
        this.users = users;
    }
    
    public List<Usere> getFindUsers() {
        users = userEjb.findAll();
        return users;
    }
    

    public String getSearch() {
        return search;
    }

    public void setSearch(String search) {
        this.search = search;
    }
    
    public void searchUsers (){
        ArrayList<Usere> temp = new ArrayList<Usere>();
        for(Usere p : getUsers()){
        if(p.getName().contains(search))
        {
        temp.add(p);
        
        }
        }
        users = temp;
    }
}
